import java.sql.*;

public class JDBCDemoSelect {

    public static final String URL = "jdbc:mysql://localhost:3306/mydatabase?serverTimezone=GMT-8&useUnicode=true&characterEncoding=utf-8";

    public static final String UserName ="root";

    public static final String PassWord = "12345678";

    public static void TestConnection(){
        try(Connection conn= DriverManager.getConnection(URL,UserName, PassWord)) {

            System.out.println(conn);
            //获得命令对象
            Statement statement=conn.createStatement();
            System.out.println("连接成功");
            //执行查询命令
            ResultSet rs = statement.executeQuery("select * from t_user");
            //遍历结果集
            while (rs.next()){
                System.out.println("==========================================================================");
                int Id=rs.getInt("id");
                String Name=rs.getString("username");
                String password=rs.getString("password");


                System.out.println(Id+"\t"+Name+"\t"+password+"\t");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        TestConnection();
    }
}
